var petname = $.cookie('petname')
console.log(petname)

if (petname) {
    $(' .aimg img').attr({ 'src': '/uploads/' + petname + '.jpg', 'onerror': "this.src='../images/user.png'" }).css({ 'borderRadius': '50%', 'width': '70px' })
    $('#jilu').text('登录成功')
    $(' .aimg span').text(petname)
    $('.fa:eq(0)').text('上传').attr('href', 'user/photo.html')
    $('.fa:eq(1)').text('发布').attr('href', 'ask.html')
    $('.fa:eq(2)').text('退出').attr('href', '/user/signout')
} else {
    $('.active:eq(1) a').attr('href', 'user/signin.html')
    $('.active:eq(2) a').attr('href', 'user/signin.html')
    $('.index p').removeAttr('ng-click')
    $('#jilu').text('登出成功')
    $('.fa:eq(0)').text('登录').attr('href', 'user/signin.html')
    $('.fa:eq(1)').text('注册').attr('href', '/user/register.html')
    $('.fa:eq(2)').text('').removeAttr('href')
}
var app = angular.module('myApp', [])
app.controller('Ctrol', ['$scope', '$http', function($scope, $http) {
    $http.get('/api/index').then(function(res) {
        if (res.status == 200) {
            console.log(res.data.Data.questions)
            angular.extend($scope, res.data.Data)
        }
    })
    $scope.show = function(id) {
        $.cookie('id', id)
        console.log($.cookie('id'))
            //     // 跳转
        location.href = 'answer.html'
    }
}])
app.directive('errSrc', function() {
    return {
        link: function(scope, element, attrs) {
            element.bind('error', function() {
                if (attrs.src != attrs.errSrc) {
                    attrs.$set('src', attrs.errSrc);
                }
            });
        }
    }
});